<?php 
namespace app\api\controller;


use think\Request;
use app\api\validate\Message as MessageValidate;
use app\api\model\Message as MessageModel;
use app\lib\exception\SuccessMessage;
use app\lib\exception\FailMessage;

/**
 * 加盟留言
 */
class Message
{
	
	/*
	添加加盟留言
	*/
	public function joinMessage()
	{
        (new MessageValidate())->goCheck();

        $request = Request::instance();
        $params = $request->param();

        $result = $this->doJoinMessage($params);

        if($result){
			return new SuccessMessage();
		}else{
            return new FailMessage();
        }
	}

	/*
	 * 处理添加加盟留言
	 */
	public function doJoinMessage($params)
    {
    	$message = new MessageModel();
    	$message->name = $params['name'];
    	$message->phone = $params['phone'];
    	$message->address = $params['address'];
    	$message->message = $params['message'];

    	$message->save();

    	return $message->id;
    }
}
